<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <meta charset="utf-8">
    <link rel="shortcut icon" href="#"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css">
    <script src="${pageContext.request.contextPath}/layui/layui.js"></script>
    <style type="text/css">
        .show {
            width: 90%;
            height: 210px;
            border-radius: 30px;
            background-color: #5bc0de;
            margin: 20px 20px 20px 30px;
        }

        .rooms {
            width: 100%;
            height: 250px;
        }

        .detail {
            width: 90%;
            height: 250px;
            margin: 20px 20px 20px 10px;
            padding-top: 20px;
        }

        .container {
            width: 90%;
        }
    </style>
</head>

<body>
<div class="layui-tab layui-tab-brief " lay-filter="docDemoTabBrief">
    <ul class="layui-tab-title" id="rtype"></ul>
    <div class="layui-tab-content" style="height: 100px;" id="room-content">
    </div>
</div>

<div id="ruzhu" style="display: none" lay-filter="test1">
    <div class="grid-demo" style="margin-top: 20px;">
        <form class="layui-form" action="" id="showInfo" lay-filter="rzdetail">
            <div class="layui-form-item" style="display: none">
                <label class="layui-form-label">详情id</label>
                <div class="layui-input-inline">
                    <input type="text" name="id" required lay-verify="required" autocomplete="off"
                           class="layui-input" disabled>
                </div>
            </div>
            <div class="layui-form-item" style="display: none">
                <label class="layui-form-label">身份证号</label>
                <div class="layui-input-inline">
                    <input type="text" name="idcard" required lay-verify="required" autocomplete="off"
                           class="layui-input" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">订单号</label>
                <div class="layui-input-inline">
                    <input type="text" name="orderid" required lay-verify="required" autocomplete="off"
                           class="layui-input" disabled>
                </div>
            </div>
            <div class="layui-form-item" style="display: none">
                <label class="layui-form-label">房间号</label>
                <div class="layui-input-inline">
                    <input type="text" name="roomid" required lay-verify="required" autocomplete="off"
                           class="layui-input" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">姓名</label>
                <div class="layui-input-inline">
                    <input type="text" name="uname" required lay-verify="required" autocomplete="off"
                           class="layui-input" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">电话</label>
                <div class="layui-input-inline">
                    <input type="text" name="tel" required lay-verify="required" autocomplete="off"
                           class="layui-input" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">入住时间</label>
                <div class="layui-input-inline">
                    <input type="date" name="indate" required lay-verify="required" autocomplete="off"
                           class="layui-input" disabled>
                </div>
            </div>
            <div class="layui-form-item" style="display: none">
                <label class="layui-form-label">`入住押金`:</label>
                <div class="layui-input-inline">
                    <input type="text" name="rzyj" required lay-verify="required" autocomplete="off"
                           class="layui-input" disabled>
                </div>
            </div>
            <div class="layui-form-item" style="display: none">
                <label class="layui-form-label">经办人</label>
                <div class="layui-input-inline">
                    <input type="hidden" name="rzjbr" required lay-verify="required" autocomplete="off"
                           class="layui-input" value="101" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">已住/天:</label>
                <div class="layui-input-inline">
                    <input type="text" name="yizhu" required lay-verify="required" autocomplete="off"
                           class="layui-input" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">还剩/天:</label>
                <div class="layui-input-inline">
                    <input type="text" name="shengyu" required lay-verify="required" autocomplete="off"
                           class="layui-input" disabled>
                </div>
            </div>
        </form>
    </div>
</div>
<div id="roomdetails" style="display: none"></div>

<div id="xuzhuinfo" style="display: none">
    <form class="layui-form" action="" lay-filter="xufang">
        <input type="text" id="rzdate" name="begintime"/>
        <input type="text" id="leavedate" name="endtime">
        <input type="hidden" id="roomtype" name="roomtype">
        <input type="hidden" name="orderid">
        <span id="money" style="display: none"></span>
        <div class="layui-form-item" style="display: none">
            <label class="layui-form-label">入住id</label>
            <div class="layui-input-inline">
                <input type="text" name="ruzhuid" required lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <%--        <div class="layui-form-item">--%>
        <%--            <label class="layui-form-label">电话</label>--%>
        <%--            <div class="layui-input-inline">--%>
        <%--                <input type="text" name="tel" required lay-verify="required|phone|number" placeholder="请输入电话"--%>
        <%--                       autocomplete="off" class="layui-input">--%>
        <%--            </div>--%>
        <%--        </div>--%>
        <div class="layui-form-item">
            <label class="layui-form-label">时间</label>
            <div id="test3"></div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">总价:</label>
            <span id="dcount" style="display: none"></span>
            <div class="layui-input-inline">
                <span id="totalPrice" style="color: red; font-size: 20px"></span>
                <input type="hidden" name="money" id="price">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo1" id="opera">续房</button>
                <%--                <button type="reset" class="layui-btn layui-btn-primary">重置</button>--%>
            </div>
        </div>
    </form>
</div>


<div id="tuifang" style="display: none">
    <form class="layui-form" action="" lay-filter="tuifanginfo">
        <div class="layui-form-item" style="display: none">
            <label class="layui-form-label">入住详情号</label>
            <div class="layui-input-inline">
                <input type="text" name="ruzhuid" required autocomplete="off"
                       class="layui-input" disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">订单号</label>
            <div class="layui-input-inline">
                <input type="text" name="orderid" required autocomplete="off"
                       class="layui-input" disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">退宿时间</label>
            <div class="layui-input-inline">
                <input type="text" name="outdate" required autocomplete="off"
                       class="layui-input" disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">退还金额/元</label>
            <div class="layui-input-inline">
                <input type="text" name="tsmoney" required autocomplete="off"
                       class="layui-input" disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">退还押金/元</label>
            <div class="layui-input-inline">
                <input type="text" name="tsyj" required autocomplete="off"
                       class="layui-input" disabled>
            </div>
        </div>
        <div class="layui-form-item" style="display: none">
            <label class="layui-form-label">经办人</label>
            <div class="layui-input-inline">
                <input type="hidden" name="tsjbr" required autocomplete="off"
                       class="layui-input" value="${sessionScope.id}" disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-inline">
                <input type="text" name="comm" required autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="tfForm">退房</button>
            </div>
        </div>
    </form>
</div>


<script id="demo" type="text/html">
    <div class="container">
        <div class="layui-row">
            {{# layui.each(d.list, function(index, item){ }}
            <div class="layui-col-md2">
                <div class="rooms">
                    <div class="show">
                        <div class="detail">
                            <span style="font-size: 30px; color: whitesmoke">{{ item.roomcode }}</span><br>
<%--                            <span style="font-size: 15px; color: whitesmoke">房间状态: {{ item.status }}</span><br>--%>
                            <div class="layui-btn-container" style="margin-top: 20px">
                                {{# if(item.status==0) { }}
                                <button type="button" class="layui-btn layui-btn-primary">可入住
                                </button>
                                {{# } }}
                                {{# if(item.status == 1 ) { }}
                                <button type="button" class="layui-btn layui-btn-normal"
                                        onclick="dasao('{{item.id}}','{{item.typeid}}')">待打扫
                                </button>
                                {{# } }}
                                {{# if(item.status == 2 ) { }}
                                <button type="button" class="layui-btn layui-btn-primary"
                                        onclick="xiangqing('{{item.id}}')">详情
                                </button>
                                <button type="button" class="layui-btn layui-btn-warm"
                                        onclick="huanfang('{{item.id}}','{{item.typeid}}')">换房
                                </button>
                                <button type="button" class="layui-btn layui-btn-normal"
                                        onclick="xufang('{{item.id}}','{{item.typeid}}')">续房
                                </button>
                                <button type="button" class="layui-btn layui-btn-danger"
                                        onclick="tuifang('{{item.id}}')">退房
                                </button>
                                {{# } }}
                                {{# if(item.status==3) { }}
                                <button type="button" class="layui-btn layui-btn-primary"
                                        onclick="sunhuai('{{item.id}}')">报修
                                </button>
                                {{# } }}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            {{# }); }}
        </div>
    </div>
</script>


<script id="huan" type="text/html">
    <div class="container">
        <div class="layui-row">
            {{# layui.each(d.list, function(index, item){ }}
            <div class="layui-col-md3">
                <div class="rooms">
                    <div class="show">
                        <div class="detail">
                            <span style="font-size: 30px; color: whitesmoke">{{ item.roomcode }}</span><br>
<%--                            <span style="font-size: 15px; color: whitesmoke">房间状态: {{ item.status }}</span><br>--%>
                            <div class="layui-btn-container" style="margin-top: 20px">
                                <button type="button" class="layui-btn layui-btn-primary"
                                        onclick="ruzhu('{{item.id}}')">入住
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            {{# }); }}
        </div>
    </div>
</script>

<script>
    var layer;
    var $;
    var element;
    var form;
    var laytpl;
    var laydate;
    var initLayDate = "";
    //剩余的房间数和日期
    var syDateAndCount = "";
    layui.use(['element', 'jquery', 'laytpl', 'layer', 'form', 'laydate'], function () {
        $ = layui.jquery;
        element = layui.element;
        laytpl = layui.laytpl;
        layer = layui.layer;
        form = layui.form;
        laydate = layui.laydate;
        var flage = false;

        /**
         *初始化日期组件 默认几个日期不可用
         */
        initLayDate = {
            getRiLi: function (removedate) {
                var tt = new Object();
                if (removedate == "") {
                    //removedate=['2020-12-12','2020-12-23','2020-12-14'];
                    $("#test3").empty();
                    laydate.render({
                        elem: '#test3',
                        min: 0,
                        position: 'static',
                        mark: tt,
                        range: '~',
                        change: function (value) {
                            //给日期赋值
                            setValforDate(value);
                        }
                    });
                } else {
                    $("#test3").empty();
                    for (var i = 0; i < removedate.length; i++) {
                        var sdate = removedate[i]; //记录时间
                        var date_array = sdate.split("-");
                        var date_day = date_array[2]; //取日期的天比如2017-09-11取11
                        tt[removedate[i]] = '<span style="color:#666;font-size: 14px;"><i class="layui-icon layui-icon-heart-fill" style="color:rgba(238, 143, 92, 0.8); position:absolute; left: 5px;font-size: 28px;z-index:-1;"></i>' + Number(date_day) + '</span>';

                        //初始日期控件
                    }
                    laydate.render({
                        elem: '#test3',
                        min: 0,
                        position: 'static',
                        mark: tt,
                        range: '~',
                        ready: function (value) {
                            var mm = value.year + '-' + value.month + '-' + value.date;
                            $.each(removedate, function (index, item) {
                                var item = changeTime(item);
                                //$('.layui-laydate table tbody').find('[lay-ymd="' + item + '"]').addClass('laydate-disabled');
                            })
                        },
                        change: function (value) {
                            flage = false;
                            var dateTime = value.split('~');
                            var startTime = dateTime[0].replace(/-/g, "/");
                            var endTime = dateTime[1].replace(/-/g, "/");

                            var s = Date.parse(startTime);
                            var e = new Date(endTime).getTime();
                            //如果选择的时间段之内有房间已满的情况就不允许选择
                            $.each(removedate, function (index, item) {
                                var disabletime = item.replace(/-/g, "/");
                                var f = isDuringDate(s, e, disabletime);
                                if (f) {
                                    flage = true;
                                }
                                //var item=changeTime(item);
                                //$('.layui-laydate table tbody').find('[lay-ymd="' + item + '"]').addClass('laydate-disabled');

                            })
                            if (!flage) {
                                setValforDate(value);
                            } else {
                                layer.msg("当前时间段之内有的房间已满")
                            }

                        }
                    });
                }
            }
        }

        $(function () {
            $.ajax({
                url: "${pageContext.request.contextPath}/order/roomtype",
                dataType: "JSON",
                data: {},
                async: false,
                success: function (data) {
                    $("#rtype").empty();
                    $("#room-content").empty();
                    $.each(data, function (index, obj) {
                        let title = "";
                        let content = "";
                        if (index == 0) {
                            content = '<div class="layui-tab-item layui-show" id="room' + obj.id + '"></div>';
                            title = '<li class="layui-this" lay-id="' + obj.id + '" >' + obj.name + '</li>';
                        } else {
                            content = '<div class="layui-tab-item" id="room' + obj.id + '"></div>';
                            title = '<li lay-id="' + obj.id + '" >' + obj.name + '</li>';
                        }
                        $("#rtype").append(title);
                        $("#room-content").append(content)
                    })
                }
            });
        })

        element.on("tab(docDemoTabBrief)", function () {
            let typeid = this.getAttribute('lay-id');
            let roomlist = getRoomListByStatus(typeid, "0,1,2,3");
            var data = { //数据
                "title": "客房"
                , "list": roomlist
            }
            var getTpl = demo.innerHTML;
            var view = document.getElementById('room' + this.getAttribute('lay-id'));
            laytpl(getTpl).render(data, function (html) {
                view.innerHTML = html;
            });
        })


        form.on('submit(tfForm)', function (data) {
            $.ajax({
                url: "${pageContext.request.contextPath}/tfang/append",
                type: "POST",
                dataType: "JSON",
                data: data.field,
                async: false,
                success: function (text) {
                    layer.msg("hello world");
                    location.reload();
                }
            });
            return false;
        })
    });

    //某个时间段室内是否含有这个时间如果含有就返回true 否则就false
    function isDuringDate(beginDateStr, endDateStr, dateStr) {
        var curDate = new Date(dateStr),
            beginDate = new Date(beginDateStr),
            endDate = new Date(endDateStr);
        if (curDate >= beginDate && curDate < endDate) {
            return true;
        }
        return false;
    }

    //获取房间的详情 data-->房型
    function getDetail(data) {
        var syAndManDate = "";
        $.ajax({
            url: "${pageContext.request.contextPath}/xufang/findTypeById",
            type: "post",
            data: {typeid: data},
            dataType: "json",
            async: false,
            success: function (da) {
                // alert(JSON.stringify(da));
                //类型的信息
                var d = da.typeMess;
                $("#roomtype").val(d.roomtype);
                // alert(d.money);
                $("#money").text(d.money);
                // alert(d.id);
                //已满的日期  以及每天还剩多少房
                syAndManDate = da.orderMess;
                // alert(JSON.stringify(syAndManDate));
            }
        });

        //加载日历框
        //syAndManDate如果为空证明这个类型的房间还没有被预定过
        if (syAndManDate == undefined) {
            initLayDate.getRiLi('');
        } else {
            //
            syDateAndCount = syAndManDate.srDate;
            initLayDate.getRiLi(syAndManDate.manDate);
            //获取日期  以及他们对应的剩余的房间数

        }

    }

    function setValforDate(value) {
        let val = $("#rzdate").val();
        var dateTime = value.split('~');
        // var startTime = dateTime[0].replace(/-/g, "/");
        var startTime = val.replace(/-/g, "/");
        var endTime = dateTime[1].replace(/-/g, "/");

        // var startTime1 = dateTime[0];
        var startTime1 = val;
        var endTime1 = dateTime[1];
        var s = Date.parse(startTime);
        var e = new Date(endTime).getTime();
        //计算两个时间间隔天数
        var d = (Number(e) - Number(s)) / (1000 * 60 * 60 * 24);
        // if (d > 15) {
        //     layer.msg('最多选择15天');
        // }
        if (d < 1) {
            layer.msg("您至少需要续住1天,您的离店时间为" + val);
            $("#price").val(0);
            $("#totalPrice").html(0 + "元");
        } else if (d > 15) {
            layer.msg('最多选择15天');
            $("#price").val(0);
            $("#totalPrice").html(0 + "元");
        }
        $("#dcount").text(d);
        // 不用给开始时间赋值
        $("#rzdate").val($.trim(startTime1));
        $("#leavedate").val($.trim(endTime1));

        // 获取价格
        let jg = Number($("#money").text());
        // 获取共住几天
        let dcount = Number($("#dcount").text());
        // 获得共几天
        let total = dcount * jg;
        $("#price").val(total);
        $("#totalPrice").html(total + "元");
    }

    function changeTime(times) {
        var time = times.split("-");
        var year = time[0];
        var month = time[1];
        if (Number(month) < 10) {
            //将数据库中传过来的01变为1
            month = Number(month);
            //alert(Number(month));
        }
        var day = time[2];
        if (Number(day) < 10) {
            //将数据库中传过来的01变为1
            day = Number(day);
        }
        var item = year + "-" + month + "-" + day;
        return item;
    }

    // 获取的数据: 入住详情id, 换房时间, 旧的房间号 新的房间号
    function ruzhu(id) {
        layer.confirm('是否入住' + id + '号房?', {
            btn: ['是', '否'] //按钮
        }, function () {
            // 往后台传数据
            // alert("入住"+id);
            // id 即为新的房间号 获取到原来房间的信息
            var datas = form.val("rzdetail");
            // form.val("rzdetail",{"roomid":id});
            // 填充换房记录表中的数据
            let data = new Object();
            data.ruzhuid = datas.id;
            data.time = (new Date()).toLocaleDateString().replaceAll("/", "-");
            data.oldroomid = datas.roomid;
            data.newroomid = id;
            $.ajax({
                url: "${pageContext.request.contextPath}/changeroom/add",
                dataType: "JSON",
                data: data,
                async: false,
                success: function (data) {
                    if (data < 0) {
                        layer.msg("换房失败，换房次数已上限");
                    } else {
                        layer.msg("换房成功");
                    }
                }
            });

            <%--// 更改原来信息中的房间的信息--%>
            <%--datas.roomid = id;--%>
            <%--alert(JSON.stringify(datas));--%>
            <%--// 通过ajax将数据传到后台--%>
            <%--$.ajax({--%>
            <%--    url: "${pageContext.request.contextPath}/ruzhu/append",--%>
            <%--    dataType: "JSON",--%>
            <%--    data: datas,--%>
            <%--    async: false,--%>
            <%--    success: function () {--%>
            <%--    }--%>
            <%--});--%>

            // layer.closeAll();
        }, function () {
            layer.msg('恭喜你发现了一个彩蛋,可惜没有奖励', {
                time: 20000, //20s后自动关闭
                btn: ['明白了', '知道了']
            });
        });
    }

    function xufang(id, typeid) {
        // xuzhuinfo

        let details = getdetails(id);
        if (details.status == 0) {
            $("#rzdate").val(details.outdate);
            //     alert(JSON.stringify(details));
            //    alert(details.id);
            getDetail(typeid);
            var index = layer.open({
                title: '续房展示',
                type: 1,
                content: $("#xuzhuinfo"),
                area: ['320px', '195px'],
                maxmin: true
            });
            layer.full(index);
            // typeid
            form.val("xufang", {'roomtype': typeid, 'ruzhuid': details.id, 'orderid': details.orderid});

            form.on('submit(formDemo1)', function (data) {
                let dates = details.outdate.split("-");
                var s = (new Date()).setFullYear(Number(dates[0]), Number(dates[1]) - 1, Number(dates[2]));
                let datee = data.field.endtime.split("-");
                var e = (new Date()).setFullYear(Number(datee[0]), Number(datee[1]) - 1, Number(datee[2]));

                $.ajax({
                    url: "${pageContext.request.contextPath}/xufang/addRuZhu",
                    type: "POST",
                    dataType: "JSON",
                    data: data.field,
                    async: false,
                    success: function (text) {
                        // alert(text);
                        layer.msg("hello world");
                        $("#rzdate").val("");
                        $("#leavedate").val("");
                        // location.reload();
                        layer.closeAll();
                    }
                });
                return false;
            });
        } else {
            layer.msg("您已有过一次续房记录,不能再次续房", {icon: 1});
        }

    }

    function getRoomListByStatus(typeid, status) {
        let roomlist = "";
        $.ajax({
            url: "${pageContext.request.contextPath}/order/getRoomByTid",
            dataType: "JSON",
            data: {id: typeid, status: status},
            async: false,
            success: function (text) {
                roomlist = text;
            }
        });
        return roomlist;
    }

    function huanfang(id, typeid) {
        // 获取所有可用的房间类型
        let roomlist = getRoomListByStatus(typeid, "0");
        // alert(JSON.stringify(roomlist));
        if (roomlist.length > 0) {
            var data = { //数据
                "title": "客房"
                , "list": roomlist
            }
            // 通过模板法进行渲染
            var getTpl = huan.innerHTML;
            var view = document.getElementById('roomdetails');
            laytpl(getTpl).render(data, function (html) {
                view.innerHTML = html;
            });
            // 填充展示表单的数据 保存换房前的信息
            let roomdata = getdetails(id);
            // alert(JSON.stringify(roomdata));
            form.val('rzdetail', roomdata);
            let yizhu = setValueforDate(roomdata.indate);
            let shengyu = setValueforDate(roomdata.outdate);
            form.val('rzdetail', {'yizhu': yizhu, 'shengyu': shengyu});
            if (shengyu > 0) {
                var index = layer.open({
                    title: '房间类型展示',
                    type: 1,
                    content: $("#roomdetails"),
                    area: ['320px', '195px'],
                    maxmin: true
                });
                layer.full(index);
            } else {
                layer.msg("今天就退房了，小老弟想搞事?", {icon: 1});
            }
        } else {
            layer.msg('该类型房间已满房', {icon: 1});
        }
    }

    // 退房  退房时间
    function tuifang(id) {
        // id 为房间的id 通过房间的id查出入住详情 通过入住详情获得获得到对应的订单以及房间类型获得到对应房间的押金以及价格
        // 先计算出已住多少天,还剩多少天,以及是否是订单入住
        // 价格
        let details = getdetails(id);
        form.val("tuifanginfo", details);

        let symoney = 0;
        let now = new Date();

        // 先判断是否为当前时间 再判断是否大于当前时间 (new Date()).toLocaleDateString().replaceAll("/", "-")
        let dates = details.outdate.split("-");
        var s = (new Date()).setFullYear(Number(dates[0]), Number(dates[1]) - 1, Number(dates[2]));
        if (s > now.getTime()) {
            let nhour = now.getHours();
            let sy = setValueforDate(details.outdate);
            if (nhour > 14) {
                symoney = (sy - 1) * details.money + details.money * 0.5;
            } else {
                symoney = sy * details.money;
            }
        }
        let datetime = (new Date()).toLocaleDateString().replaceAll("/", "-");
        form.val("tuifanginfo", {
            'ruzhuid': details.id,
            'tsmoney': symoney,
            'outdate': datetime,
            'tsyj': details.rzyj
        });

        layer.open({
            title: '退房记录',
            type: 1,
            content: $("#tuifang"),
            area: ['400px', '400px']
        });

        form.on('submit(tfForm)', function (data) {
            $.ajax({
                url: "${pageContext.request.contextPath}/tfang/append",
                type: "POST",
                dataType: "JSON",
                data: data.field,
                async: false,
                success: function (text) {
                    layer.msg("退房成功");
                    layer.closeAll();
                    // alert("hello world");
                }
            });
            return false;
        })
        $.ajax({
            url: "${pageContext.request.contextPath}/tfang/changeroom",
            type: "POST",
            dataType: "JSON",
            data: {id: id},
            async: false,
            success: function (text) {
                //   alert(text);
                //
            }
        });
        // layer.closeAll();
    }

    function getdetails(id) {
        let roomdata;
        $.ajax({
            url: "${pageContext.request.contextPath}/ruzhu/rzdetail",
            type: "POST",
            dataType: "JSON",
            data: {roomid: id},
            async: false,
            success: function (data) {
                if (data != null) {
                    roomdata = data;
                }
            }
        });
        return roomdata;
    }

    /**
     * 可以通过房间的id到入住详情表中将入住人的信息提取出来
     * 如果之前已经有人住过也会有记录
     * 找入住时间最大的那个(时间最大的那个 也就是最接近当前时间的，也是最近入住的用户的信息)
     * @param id
     */
    function xiangqing(id) {
        //   alert("id"+id);
        let roomdata = getdetails(id);
        form.val('rzdetail', roomdata);
        let yizhu = setValueforDate(roomdata.indate);
        let shengyu = setValueforDate(roomdata.outdate);
        form.val('rzdetail', {'yizhu': yizhu, 'shengyu': shengyu});
        layer.open({
            title: '入住详情',
            type: 1,
            area: ['400px', '500px'],
            content: $("#ruzhu") //这里content是一个普通的String
        });

    }

    function dasao(id, typeid) {
        layer.confirm('是否要呼唤保洁阿姨进行打扫?', {
            btn: ['是', '否'] //按钮
        }, function () {
            $.ajax({
                url: "${pageContext.request.contextPath}/changeroom/dasao",
                type: "POST",
                dataType: "JSON",
                data: {id: id, typeid: typeid},
                async: false,
                success: function (data) {
                    if (data > 0) {
                        layer.msg('打扫完成', {icon: 1});
                        location.reload();
                    } else {
                        layer.msg('保洁阿姨手里没有货了', {icon: 1});
                    }

                }
            });
            layer.closeAll();
        }, function () {
            layer.msg('也可以这样', {
                time: 20000, //20s后自动关闭
                btn: ['明白了', '知道了']
            });
        });
        element.init();
    }

    /**
     * 计算天数 计算(indate --已住-- now --剩余-- outdate)
     * @param value
     * @returns {number}
     */
    function setValueforDate(value) {
        let dates = value.split("-");
        var s = (new Date()).setFullYear(Number(dates[0]), Number(dates[1]) - 1, Number(dates[2]));
        var e = new Date().getTime();
        //计算两个时间间隔天数
        if (s > e) {
            var t = s;
            s = e;
            e = t;
        }
        let d = (Number(e) - Number(s)) / (1000 * 60 * 60 * 24);
        return d;
    }
</script>
</body>
</html>